package banxi.ktv.mdao;

import java.io.IOException;
import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MybatisHelper {

	private static final Logger log = LoggerFactory.getLogger(MybatisHelper.class);
	private static SqlSession sqlSession;
	
	private MybatisHelper(){}
	
	static{
		try {
			Reader reader = Resources.getResourceAsReader("mybatis/sqlMapConfig.xml");
			SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
			sqlSession = sqlSessionFactory.openSession();
		} catch (IOException e) {
			log.error("Mybatis SqlSession初始化失败.");
			e.printStackTrace();
		}
	}
	
	public static SqlSession getSqlSession(){
		return sqlSession;
	}
}
